package org.thirdeyetvg.ncanreader;

import org.thirdeyetvg.ncanreader.constants.ApplicationConstants;
import org.thirdeyetvg.ncanreader.constants.ApplicationConstants.ResultSource;
import org.thirdeyetvg.ncanreader.constants.ApplicationConstants.SupportedModes;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioButton;

public class ModeSelectionActivity extends Activity {

	private static final String TAG = ModeSelectionActivity.class.getName();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_mode_selection);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_mode_selection, menu);
		return true;
	}

	public void onButtonClick(View view) {
		Log.d(TAG, "OK clicked");
		// RadioButton normalModeRB = (RadioButton)
		// findViewById(R.id.rb_normal_mode);
		RadioButton accessibileModeRB = (RadioButton) findViewById(R.id.rb_accessible_mode);
		boolean isDefault = ((CheckBox) findViewById(R.id.cb_make_default))
				.isChecked();
		// boolean isNormalMode = normalModeRB.isChecked();
		boolean isAccessibleMode = accessibileModeRB.isChecked();
		SupportedModes selectedMode = null;
		if (isAccessibleMode) {
			selectedMode = SupportedModes.accessible;
			Log.d(TAG, "Accessible Mode");
		} else {
			selectedMode = SupportedModes.normal;
			Log.d(TAG, "Normal Mode");
		}
		Log.d(TAG, "isDefault:" + isDefault);
		// TODO Set isDefault in preference
		Intent result = new Intent();
		result.putExtra(ApplicationConstants.RESULT,
				ResultSource.mode_selection.toString());
		result.putExtra("data", selectedMode.toString());
		setResult(RESULT_OK, result);
		finish();
	}

}
